package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelPromotionBasicInfo;
import com.yunxin.core.domain.model.channel.ChannelPromotionBasicInfoRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelPromotionBasicInfoDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelPromotionBasicInfoExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class ChannelPromotionBasicInfoRepositoryImpl implements ChannelPromotionBasicInfoRepository {

    private final ChannelPromotionBasicInfoExtendMapper channelPromotionBasicInfoExtendMapper;

    private final ChannelConvertor channelConvertor;
    @Override
    public boolean saveChannelPromotionBasicInfo(ChannelPromotionBasicInfo channelPromotionBasicInfo) {
        ChannelPromotionBasicInfoDO channelPromotionBasicInfoDO = channelConvertor.formChannelPromotionBasicInfo(channelPromotionBasicInfo);
        channelPromotionBasicInfoDO.setProtocolStatus(channelPromotionBasicInfo.getProtocolStatus());
        int count = channelPromotionBasicInfoExtendMapper.insertSelective(channelPromotionBasicInfoDO);
        return count > 0;
    }

    @Override
    public boolean updateChannelPromotionBasicInfo(ChannelPromotionBasicInfo channelPromotionBasicInfo) {
        ChannelPromotionBasicInfoDO channelPromotionBasicInfoDO = channelConvertor.formChannelPromotionBasicInfo(channelPromotionBasicInfo);
        channelPromotionBasicInfoDO.setProtocolStatus(channelPromotionBasicInfo.getProtocolStatus());
        int count = channelPromotionBasicInfoExtendMapper.updateByPromotionIdSelective(channelPromotionBasicInfoDO);
        return count > 0;
    }
}
